<Project InitialTargets="PrintHelixQueues;PrintBuildTargetFramework;BuildHelixWorkItems" Sdk="Microsoft.DotNet.Helix.Sdk">

  <!-- This project uses the Helix SDK, documented at
       https://github.com/dotnet/arcade/tree/master/src/Microsoft.DotNet.Helix/Sdk,
       to send test jobs to Helix.
  -->
  <PropertyGroup>
    <WindowsShell Condition="'$(TargetOS)' == 'windows' or '$(BrowserHost)' == 'windows' or ($(TargetRuntimeIdentifier.ToLowerInvariant().StartsWith('linux-bionic')) and $(HelixTargetQueue.ToLowerInvariant().Contains('windows')))">true</WindowsShell>

    <!-- Set Helix build to build number if available -->
    <HelixBuild Condition="'$(HelixBuild)' == ''">$(BUILD_BUILDNUMBER)</HelixBuild>
    <HelixBuild Condition="'$(HelixBuild)' == ''">default</HelixBuild>

    <HelixConfiguration>$(Configuration)</HelixConfiguration>
    <HelixArchitecture>$(TargetArchitecture)</HelixArchitecture>
    <BuildHelixWorkItemsDependsOn>BuildHelixCommand;StageDependenciesForHelix</BuildHelixWorkItemsDependsOn>
    <EnableDefaultBuildHelixWorkItems>true</EnableDefaultBuildHelixWorkItems>
    <HelixDependenciesStagingPath>$([MSBuild]::NormalizeDirectory($(ArtifactsObjDir), 'helix-staging'))</HelixDependenciesStagingPath>
  </PropertyGroup>

  <Import Project="$(MSBuildThisFileDirectory)sendtohelix-wasi.targets" Condition="'$(TargetOS)' == 'wasi'" />
  <Import Project="$(MSBuildThisFileDirectory)sendtohelix-browser.targets" Condition="'$(TargetOS)' == 'browser'" />
  <Import Project="$(MSBuildThisFileDirectory)sendtohelix-mobile.targets" Condition="'$(TargetsMobile)' == 'true' and '$(TargetOS)' != 'browser' and '$(TargetOS)' != 'wasi'" />
  <Import Project="$(MSBuildThisFileDirectory)sendtohelix-superpmi-collect.targets" Condition="'$(SuperPmiCollect)' == 'true'" />

  <PropertyGroup Condition="'$(_workItemTimeout)' == ''">
    <!-- Normal jobs have a 30 minute timeout for arm/arm64, and 15 minute timeout otherwise.
         Stress modes can take considerably longer, so double those numbers. And GCStress is even slower.
    -->
    <_workItemTimeout Condition="
        '$(Scenario)' == 'gcstress0x3' or
        '$(Scenario)' == 'gcstress0xc' or
        '$(Scenario)' == 'heapverify1' or
        '$(Scenario)' == 'gcstress0xc_disabler2r' or
        '$(Scenario)' == 'gcstress0xc_disabler2r_jitstress2' or
        '$(Scenario)' == 'gcstress0xc_disabler2r_heapverify1' or
        '$(Scenario)' == 'gcstress0xc_jitstress1' or
        '$(Scenario)' == 'gcstress0xc_jitstress2' or
        '$(Scenario)' == 'gcstress0xc_jitminopts_heapverify1'">06:00:00</_workItemTimeout>
    <_workItemTimeout Condition="'$(_workItemTimeout)' == '' and '$(TargetsAppleMobile)' == 'true'">01:15:00</_workItemTimeout>
    <_workItemTimeout Condition="'$(_workItemTimeout)' == '' and '$(TargetOS)' == 'android'">00:30:00</_workItemTimeout>
    <_workItemTimeout Condition="'$(Scenario)' == '' and '$(_workItemTimeout)' == '' and ('$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'arm')">00:45:00</_workItemTimeout>
    <_workItemTimeout Condition="'$(Scenario)' != '' and '$(_workItemTimeout)' == '' and ('$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'arm')">01:00:00</_workItemTimeout>
    <_workItemTimeout Condition="'$(Scenario)' == '' and '$(_workItemTimeout)' == '' and ('$(TestScope)' == 'outerloop' or '$(TestScope)' == 'all')">00:20:00</_workItemTimeout>
    <_workItemTimeout Condition="'$(Scenario)' == '' and '$(_workItemTimeout)' == ''">00:15:00</_workItemTimeout>
    <_workItemTimeout Condition="'$(Scenario)' != '' and '$(_workItemTimeout)' == ''">00:30:00</_workItemTimeout>
  </PropertyGroup>

  <PropertyGroup>
    <!-- The Helix runtime payload and the tests to run -->
    <!-- TestArchiveRuntimeFile will be passed as a property by the calling project -->
    <HelixCorrelationPayload Condition="'$(HelixCorrelationPayload)' == ''">$(TestArchiveRuntimeFile)</HelixCorrelationPayload>
    <WorkItemArchiveWildCard Condition="'$(WorkItemArchiveWildCard)' == ''">$(TestArchiveTestsRoot)**/*.zip</WorkItemArchiveWildCard>

    <!-- This property is used to show the tests results in Azure Dev Ops. By setting this property the
         test run name will be displayed as $(BuildTargetFramework)-$(TargetOS)-$(Configuration)-$(TargetArchitecture)-$(HelixTargetQueue)

         In the multi-scenario case, we append the scenario name to this test name prefix to distinguish the different scenario results.
    -->
    <TestRunNamePrefix>$(BuildTargetFramework)-$(TargetOS)-$(Configuration)-$(TargetArchitecture)-</TestRunNamePrefix>
    <TestRunNamePrefix Condition="'$(TestRunNamePrefixSuffix)' != ''">$(TestRunNamePrefix)$(TestRunNamePrefixSuffix)-</TestRunNamePrefix>
    <TestRunNamePrefix Condition="'$(Scenario)' != ''">$(TestRunNamePrefix)$(Scenario)-</TestRunNamePrefix>

    <FailOnTestFailure Condition="'$(FailOnTestFailure)' == '' and '$(WaitForWorkItemCompletion)' != ''">$(WaitForWorkItemCompletion)</FailOnTestFailure>

    <SdkForWorkloadTestingDirName Condition="'$(SdkForWorkloadTestingDirName)' == '' and '$(NeedsWorkload)' == 'true' and '$(TestUsingWorkloads)' == 'true'">dotnet-latest</SdkForWorkloadTestingDirName>
    <SdkForWorkloadTestingDirName Condition="'$(SdkForWorkloadTestingDirName)' == '' and '$(NeedsWorkload)' == 'true' and '$(TestUsingWorkloads)' != 'true'">dotnet-none</SdkForWorkloadTestingDirName>
  </PropertyGroup>

  <PropertyGroup Condition="'$(HelixType)' == ''">
    <!-- For PRs we want HelixType to be the same for all frameworks except package testing-->
    <TestScope Condition="'$(TestScope)' == ''">innerloop</TestScope>
    <HelixType>test/functional/cli/$(TestScope)/</HelixType>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetOS)' == 'browser' or '$(TargetOS)' == 'wasi' or '$(TargetOS)' == 'android' or '$(TargetOS)' == 'ios' or '$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'tvos' or '$(TargetOS)' == 'tvossimulator' or '$(TargetOS)' == 'maccatalyst'">
    <IncludeXHarnessCli>true</IncludeXHarnessCli>
    <!-- XHarness telemetry not supported with custom WASM workloads yet -->
    <EnableXHarnessTelemetry Condition="'$(TargetOS)' == 'browser' or '$(TargetOS)' == 'wasi'">false</EnableXHarnessTelemetry>
  </PropertyGroup>

  <ItemGroup Condition="'$(MonoEnvOptions)' != ''">
    <HelixPreCommand Condition="'$(WindowsShell)' == 'true'" Include="set MONO_ENV_OPTIONS='$(MonoEnvOptions)'" />
    <HelixPreCommand Condition="'$(WindowsShell)' != 'true'" Include="export MONO_ENV_OPTIONS='$(MonoEnvOptions)'" />
  </ItemGroup>

  <ItemGroup Condition="'$(WindowsShell)' == 'true'">
    <HelixPreCommand Include="taskkill.exe /f /im corerun.exe"/>
    <HelixPostCommand Include="taskkill.exe /f /im corerun.exe"/>
  </ItemGroup>

  <PropertyGroup Condition="'$(NeedsWorkload)' == 'true'">
    <NeedsDotNetSdk>false</NeedsDotNetSdk>
    <IncludeXHarnessCli>true</IncludeXHarnessCli>
    <EnableXHarnessTelemetry>true</EnableXHarnessTelemetry>
  </PropertyGroup>

  <PropertyGroup>
    <UseTestEnvFile Condition="'$(UseTestEnvFile)' == ''">true</UseTestEnvFile>

    <!-- Set the name of the scenario file. Note that this is only used in invocations where $(Scenario) is set
         (which is when this project is invoked to call the "CreateTestEnvFile" target).
    -->
    <TestEnvFileName></TestEnvFileName>
    <TestEnvFileName Condition=" '$(Scenario)' != '' and '$(TargetOS)' == 'windows'">SetStressModes_$(Scenario).cmd</TestEnvFileName>
    <TestEnvFileName Condition=" '$(Scenario)' != '' and '$(TargetOS)' != 'windows' and '$(TargetOS)' != 'browser' and '$(TargetOS)' != 'wasi'">SetStressModes_$(Scenario).sh</TestEnvFileName>
  </PropertyGroup>

  <ItemGroup>
    <__HelixDependenciesToStageThatDontExist Include="@(HelixDependenciesToStage)" />
    <__HelixDependenciesToStageThatDontExist Remove="@(HelixDependenciesToStage->Exists())" />
  </ItemGroup>

  <!-- HelixPreCommands is a set of commands run before the work item command. We use it here to inject
       setting up the per-scenario environment.
  -->

  <ItemGroup Condition=" '$(TargetOS)' == 'windows' ">
    <HelixPreCommand Include="set __TestArchitecture=$(TargetArchitecture)" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetOS)' != 'windows' ">
    <HelixPreCommand Include="export __TestArchitecture=$(TargetArchitecture)" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TestEnvFileName)' != '' and '$(TargetOS)' == 'windows' ">
    <HelixPreCommand Include="set __TestEnv=%HELIX_CORRELATION_PAYLOAD%\$(TestEnvFileName)" />
    <HelixPreCommand Include="type %__TestEnv%" />
    <HelixPreCommand Include="call %__TestEnv%" />
    <!-- Display the interesting DOTNET variables that are set in the environment -->
    <HelixPreCommand Include="set DOTNET" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TestEnvFileName)' != '' and '$(TargetOS)' != 'windows' ">
    <HelixPreCommand Include="export __TestEnv=$HELIX_CORRELATION_PAYLOAD/$(TestEnvFileName)" />
    <HelixPreCommand Include="cat $__TestEnv" />
    <HelixPreCommand Include=". $__TestEnv" /> <!-- Use "." not "source"; some clients appear to run scripts with "sh" not "bash" -->
    <!-- Display the interesting DOTNET variables that are set in the environment -->
    <HelixPreCommand Include="printenv | grep DOTNET" />
  </ItemGroup>

  <ItemGroup Condition="'$(NeedsWorkload)' == 'true'">
    <HelixCommandPrefixEnvVarItem Condition="'$(WindowsShell)' != 'true'" Include="PATH=$HELIX_CORRELATION_PAYLOAD/$(SdkForWorkloadTestingDirName):$PATH" />
    <HelixCommandPrefixEnvVarItem Condition="'$(WindowsShell)' == 'true'" Include="PATH=%HELIX_CORRELATION_PAYLOAD%\$(SdkForWorkloadTestingDirName)%3B%PATH%" />

    <!-- set this to a writable location so the first time experience can write create sentinels -->
    <HelixCommandPrefixEnvVarItem Condition="'$(WindowsShell)' != 'true'" Include="DOTNET_CLI_HOME=$HELIX_WORKITEM_ROOT/.dotnet" />
    <HelixCommandPrefixEnvVarItem Condition="'$(WindowsShell)' == 'true'" Include="DOTNET_CLI_HOME=%HELIX_WORKITEM_ROOT%\.dotnet" />

    <HelixCommandPrefixEnvVarItem Condition="'$(WindowsShell)' != 'true'" Include="DOTNET_ROOT=$HELIX_CORRELATION_PAYLOAD/$(SdkForWorkloadTestingDirName)" />
    <HelixCommandPrefixEnvVarItem Condition="'$(WindowsShell)' == 'true'" Include="DOTNET_ROOT=%HELIX_CORRELATION_PAYLOAD%\$(SdkForWorkloadTestingDirName)" />

    <HelixCommandPrefixEnvVarItem Condition="'$(WindowsShell)' != 'true'" Include="SDK_FOR_WORKLOAD_TESTING_PATH=%24{HELIX_CORRELATION_PAYLOAD}/$(SdkForWorkloadTestingDirName)" />
    <HelixCommandPrefixEnvVarItem Condition="'$(WindowsShell)' == 'true'" Include="SDK_FOR_WORKLOAD_TESTING_PATH=%HELIX_CORRELATION_PAYLOAD%\$(SdkForWorkloadTestingDirName)" />

    <HelixCommandPrefixEnvVarItem Include="DOTNET_CLI_TELEMETRY_OPTOUT=1" />
    <HelixCommandPrefixEnvVarItem Condition="'$(TestUsingWorkloads)' == 'true'" Include="TEST_USING_WORKLOADS=true" />
    <HelixCommandPrefixEnvVarItem Condition="'$(TestUsingWebcil)' == 'false'" Include="TEST_USING_WEBCIL=false" />
  </ItemGroup>

  <PropertyGroup Condition="$(TargetRuntimeIdentifier.ToLowerInvariant().StartsWith('linux-bionic'))">
    <IncludeXHarnessCli>true</IncludeXHarnessCli>
    <UseDotNetCliVersionFromGlobalJson>true</UseDotNetCliVersionFromGlobalJson>
    <NeedsDotNetSdk>true</NeedsDotNetSdk>
    <EnableAzurePipelinesReporter>true</EnableAzurePipelinesReporter>
  </PropertyGroup>

  <PropertyGroup Condition="'$(NeedsDotNetSdk)' == 'true'">
    <IncludeDotNetCli>true</IncludeDotNetCli>
    <DotNetCliPackageType>sdk</DotNetCliPackageType>
  </PropertyGroup>

  <ItemGroup>
    <HelixProperties Condition="'$(RuntimeFlavor)' != ''" Include="runtimeFlavor" Value="$(RuntimeFlavor)" />
    <HelixProperties Condition="'$(Scenario)' != ''" Include="scenario" Value="$(Scenario)" />
  </ItemGroup>

  <ItemGroup Condition="'$(RunGrpcTestsOnly)' == 'true' and '$(BuildGrpcServerDockerImage)' == 'true'">
    <HelixCorrelationPayload Include="$(GrpcServerDockerImageDir)" Destination="grpcserver" />
    <HelixPreCommand Include="docker load -i $HELIX_CORRELATION_PAYLOAD/grpcserver/grpcserver.tar" />
    <HelixPreCommand Include="docker run --name grpc-server -d -p 50052:50052 -p 80:80 grpc-server:latest" />
    <HelixPostCommand Include="docker stop grpc-server" />
    <HelixPostCommand Include="docker rmi -f grpc-server:latest" />
  </ItemGroup>

  <!-- Ensure that all HelixPreCommand items are ready before this -->
  <Target Name="BuildHelixCommand">
    <!-- setting DotNetCliVersion here to ensure that it is set to the intended value -->
    <PropertyGroup Condition="'$(UseDotNetCliVersionFromGlobalJson)' == 'true'">
      <GlobalJsonContent>$([System.IO.File]::ReadAllText('$(RepoRoot)global.json'))</GlobalJsonContent>
      <DotNetCliVersion>$([System.Text.RegularExpressions.Regex]::Match($(GlobalJsonContent), '(%3F&lt;="dotnet": ").*(%3F=")'))</DotNetCliVersion>
    </PropertyGroup>

    <PropertyGroup>
      <HelixPreCommands>$(HelixPreCommands);@(HelixPreCommand)</HelixPreCommands>
      <HelixPostCommands>$(HelixPostCommands);@(HelixPostCommand)</HelixPostCommands>
      <HelixCommandPrefix Condition="'$(WindowsShell)' == 'true' and @(HelixCommandPrefixEnvVarItem->Count()) > 0" >$(HelixCommandPrefix) @(HelixCommandPrefixEnvVarItem -> 'set &quot;%(Identity)&quot;', ' &amp; ')</HelixCommandPrefix>
      <HelixCommandPrefix Condition="'$(WindowsShell)' != 'true' and @(HelixCommandPrefixEnvVarItem->Count()) > 0 ">$(HelixCommandPrefix) export @(HelixCommandPrefixEnvVarItem, ' ')</HelixCommandPrefix>
      <IncludeHelixCorrelationPayload Condition="'$(IncludeHelixCorrelationPayload)' == '' and '$(HelixCorrelationPayload)' != ''">true</IncludeHelixCorrelationPayload>
    </PropertyGroup>

    <!-- create dummy console app to workaround NuGet-Migrations issue: https://github.com/dotnet/runtime/issues/80619 -->
    <PropertyGroup Condition="'$(IncludeDotNetCli)' == 'true' and '$(DotNetCliPackageType)' == 'sdk' and '$(WindowsShell)' != 'true'">
      <_WorkaroundForNuGetMigrations>((CONSOLE_TEMP_DIR=&quot;%24(mktemp -d)&quot; %3B &quot;$DOTNET_ROOT/dotnet&quot; new console -o &quot;$CONSOLE_TEMP_DIR&quot; %3B rm -rf &quot;$CONSOLE_TEMP_DIR&quot;) || true)</_WorkaroundForNuGetMigrations>

      <HelixCommandPrefix Condition="'$(HelixCommandPrefix)' != '' and '$(WindowsShell)' != 'true'">$(HelixCommandPrefix) &amp;&amp;</HelixCommandPrefix>
      <HelixCommandPrefix Condition="'$(HelixCommandPrefix)' != '' and '$(WindowsShell)' == 'true'">$(HelixCommandPrefix) &amp;</HelixCommandPrefix>

      <HelixCommandPrefix>$(HelixCommandPrefix) $(_WorkaroundForNuGetMigrations)</HelixCommandPrefix>
    </PropertyGroup>

    <PropertyGroup Condition="'$(HelixCommand)' == ''">
      <HelixCommand Condition="'$(HelixCommandPrefix)' != '' and '$(WindowsShell)' != 'true'">$(HelixCommandPrefix) &amp;&amp; </HelixCommand>
      <HelixCommand Condition="'$(HelixCommandPrefix)' != '' and '$(WindowsShell)' == 'true'">$(HelixCommandPrefix) &amp; </HelixCommand>

      <HelixCommand Condition="'$(InstallDevCerts)' == 'true' and '$(WindowsShell)' != 'true'">$(HelixCommand) dotnet dev-certs https &amp;&amp; </HelixCommand>

      <!-- on windows `dotnet dev-certs https shows a dialog, so instead install the certificate with powershell -->
      <HelixCommand Condition="'$(InstallDevCerts)' == 'true' and '$(WindowsShell)' == 'true'">$(HelixCommand) powershell -command &quot;New-SelfSignedCertificate -FriendlyName &#39;ASP.NET Core HTTPS development certificate&#39; -DnsName @(&#39;localhost&#39;) -Subject &#39;CN = localhost&#39; -KeyAlgorithm RSA -KeyLength 2048 -HashAlgorithm sha256 -CertStoreLocation &#39;Cert:\CurrentUser\My&#39; -TextExtension @(&#39;2.5.29.37={text}1.3.6.1.5.5.7.3.1&#39;,&#39;1.3.6.1.4.1.311.84.1.1={hex}02&#39;,&#39;2.5.29.19={text}&#39;) -KeyUsage DigitalSignature,KeyEncipherment&quot; &amp;&amp; </HelixCommand>

      <!--
        For Windows we need to use "call", since the command is going to be called from a batch script created by Helix.
        We "exit /b" at the end of RunTests.cmd. Helix runs some other commands after ours within the batch script,
        so if we don't use "call", then we cause the parent script to exit, and anything after will not be executed.
      -->
      <HelixCommand Condition="'$(WindowsShell)' == 'true'">$(HelixCommand)call RunTests.cmd</HelixCommand>
      <HelixCommand Condition="'$(WindowsShell)' == 'true' and '$(IncludeHelixCorrelationPayload)' == 'true'">$(HelixCommand) --runtime-path %HELIX_CORRELATION_PAYLOAD%</HelixCommand>

      <HelixCommand Condition="'$(WindowsShell)' != 'true'">$(HelixCommand)./RunTests.sh</HelixCommand>
      <HelixCommand Condition="'$(WindowsShell)' != 'true' and '$(IncludeHelixCorrelationPayload)' == 'true'">$(HelixCommand) --runtime-path "$HELIX_CORRELATION_PAYLOAD"</HelixCommand>
    </PropertyGroup>

    <!-- FIXME: is this used? -->
    <PropertyGroup Condition="'$(RuntimeFlavor)' == 'Mono'">
      <_MonoAotCrossCompilerPath>$([MSBuild]::NormalizePath($(MonoAotCrossDir), 'mono-aot-cross'))</_MonoAotCrossCompilerPath>
      <_MonoAotCrossCompilerPath Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">$(_MonoAotCrossCompilerPath).exe</_MonoAotCrossCompilerPath>
    </PropertyGroup>
    <ItemGroup Condition="'$(RuntimeFlavor)' == 'Mono'">
      <MonoAotCrossCompiler Include="$(_MonoAotCrossCompilerPath)" RuntimeIdentifier="$(TargetOS)-$(TargetArchitecture.ToLowerInvariant())" />
    </ItemGroup>
  </Target>

  <!-- XUnitLogChecker required configuration -->
  <ItemGroup Condition="Exists('$(XUnitLogCheckerLibrariesOutDir)')">
    <HelixCorrelationPayload Include="$(XUnitLogCheckerLibrariesOutDir)" />
    <HelixCorrelationPayload Condition="'$(WindowsShell)' == 'true'" Include="dotnet-sos">
      <Destination>sos</Destination>
      <Uri>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/flat2/dotnet-sos/$(DotnetSosVersion)/dotnet-sos.$(DotnetSosVersion).nupkg</Uri>
    </HelixCorrelationPayload>
  </ItemGroup>

  <PropertyGroup Condition="'$(TargetOS)' == 'windows'">
    <NtSymbolPathEnvVar>set _NT_SYMBOL_PATH=%25HELIX_CORRELATION_PAYLOAD%25%3B%25HELIX_CORRELATION_PAYLOAD%25\PDB%3B%25HELIX_CORRELATION_PAYLOAD%25\shared\$(MicrosoftNetCoreAppFrameworkName)\$(ProductVersion)</NtSymbolPathEnvVar>
    <ExecuteDotNetSos>%25HELIX_CORRELATION_PAYLOAD%25\dotnet %25HELIX_CORRELATION_PAYLOAD%25\sos\tools\net$(DotnetSosTargetFrameworkVersion)\any\dotnet-sos.dll install --architecture $(TargetArchitecture)</ExecuteDotNetSos>
    <HelixPreCommands>$(HelixPreCommands);$(NtSymbolPathEnvVar);$(ExecuteDotNetSos)</HelixPreCommands>
  </PropertyGroup>

  <!--
    Create all the Helix data to start a set of jobs. Create a set of work items, one for each libraries
    test assembly. All will have the same command line. Note that this target is listed in the
    InitialTargets for this Project. This causes it to be invoked (and the Helix data created,
    such as the HelixWorkItem item group) before Helix "Test" target is invoked (as a normal target).
  -->
  <Target Name="BuildHelixWorkItems" DependsOnTargets="$(BuildHelixWorkItemsDependsOn)">
    <Message Condition="'$(Scenario)' == ''" Importance="High" Text="Building Helix work items" />
    <Message Condition="'$(Scenario)' != ''" Importance="High" Text="Building Helix work items for scenario $(Scenario)" />
    <Message Importance="High" Text="Using TestRunNamePrefix: $(TestRunNamePrefix)" />
    <Message Condition="'$(HelixCorrelationPayload)' != ''" Importance="High" Text="Using HelixCorrelationPayload: $(HelixCorrelationPayload)" />
    <Message Importance="High" Text="Using HelixCommand: $(HelixCommand)" />
    <Message Importance="High" Text="Using HelixType: $(HelixType)" />
    <Message Importance="High" Text="Using WorkItemArchiveWildCard: $(WorkItemArchiveWildCard)" />
    <Message Importance="High" Text="Using Timeout: $(_workItemTimeout)" />

    <PropertyGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR' and '$(BUILD_BUILDID)' != ''">
      <HelixPostCommands Condition="'$(TargetOS)' == 'windows'">
        $(HelixPostCommands);
        %HELIX_PYTHONPATH% %HELIX_CORRELATION_PAYLOAD%\gen-debug-dump-docs.py -buildid $(BUILD_BUILDID) -workitem %HELIX_WORKITEM_FRIENDLYNAME% -jobid %HELIX_CORRELATION_ID% -outdir %HELIX_WORKITEM_UPLOAD_ROOT% -templatedir %HELIX_CORRELATION_PAYLOAD% -dumpdir %HELIX_DUMP_FOLDER% -productver $(ProductVersion)
      </HelixPostCommands>
      <HelixPostCommands Condition="'$(TargetOS)' != 'windows'">
        $(HelixPostCommands);
        $HELIX_PYTHONPATH $HELIX_CORRELATION_PAYLOAD/gen-debug-dump-docs.py -buildid $(BUILD_BUILDID) -workitem $HELIX_WORKITEM_FRIENDLYNAME -jobid $HELIX_CORRELATION_ID -outdir $HELIX_WORKITEM_UPLOAD_ROOT -templatedir $HELIX_CORRELATION_PAYLOAD -dumpdir $HELIX_DUMP_FOLDER -productver $(ProductVersion)
      </HelixPostCommands>
    </PropertyGroup>

    <!-- ad-hoc sign createdump on the helix machine to allow us to collect dumps -->
    <PropertyGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR' and '$(TargetOS)' == 'osx'">
      <HelixPreCommands>
        $(HelixPreCommands);
        find $HELIX_CORRELATION_PAYLOAD -name createdump | xargs -n 1 codesign -s - -f --preserve-metadata=entitlements
      </HelixPreCommands>
    </PropertyGroup>

    <Error Condition="'$(NeedsWorkload)' == 'true' and '$(TestUsingWorkloads)' == 'true' and ('$(SdkWithWorkloadForTestingPath)' == '' or !Exists($(SdkWithWorkloadForTestingPath)))"
           Text="Could not find workload at %24(SdkWithWorkloadForTestingPath)=$(SdkWithWorkloadForTestingPath)" />

    <Error Condition="'$(NeedsWorkload)' == 'true' and '$(TestUsingWorkloads)' != 'true' and ('$(SdkWithNoWorkloadForTestingPath)' == '' or !Exists($(SdkWithNoWorkloadForTestingPath)))"
           Text="Could not find workload at %24(SdkWithNoWorkloadForTestingPath)=$(SdkWithNoWorkloadForTestingPath)" />

    <ItemGroup Condition="'$(NeedsWorkload)' == 'true'">
      <HelixCorrelationPayload Include="$(SdkWithWorkloadForTestingPath)"     Destination="$(SdkForWorkloadTestingDirName)" Condition="'$(TestUsingWorkloads)' == 'true'" />
      <HelixCorrelationPayload Include="$(SdkWithNoWorkloadForTestingPath)"   Destination="$(SdkForWorkloadTestingDirName)" Condition="'$(TestUsingWorkloads)' != 'true'" />
    </ItemGroup>

    <ItemGroup>
      <HelixCorrelationPayload Condition="$(TargetRuntimeIdentifier.ToLowerInvariant().StartsWith('linux-bionic'))" Include="openssl" Uri="https://netcorenativeassets.blob.core.windows.net/resource-packages/external/android/openssl-1.1.1l-beta-1.zip" Destination="openssl" />
    </ItemGroup>

    <ItemGroup Condition="'$(EnableDefaultBuildHelixWorkItems)' == 'true'">
      <HelixCorrelationPayload Include="$(HelixCorrelationPayload)"
                               Condition="'$(IncludeHelixCorrelationPayload)' == 'true'"
                               AsArchive="$(HelixCorrelationPayload.EndsWith('.zip'))" />

      <_DefaultWorkItems Include="$(WorkItemArchiveWildCard)" Exclude="$(HelixCorrelationPayload)" />

      <HelixWorkItem Include="@(_DefaultWorkItems -> '$(WorkItemPrefix)%(FileName)')">
        <PayloadArchive>%(Identity)</PayloadArchive>
        <Command>$(HelixCommand)</Command>
        <Timeout>$(_workItemTimeout)</Timeout>
        <DownloadFilesFromResults Condition=" '$(SuperPmiCollect)' == 'true' ">$(SuperPmiCollectionName).$(SuperPmiCollectionType).$(TargetOS).$(TargetArchitecture).$(Configuration).mch;$(SuperPmiCollectionName).$(SuperPmiCollectionType).$(TargetOS).$(TargetArchitecture).$(Configuration).log</DownloadFilesFromResults>
      </HelixWorkItem>
    </ItemGroup>

    <ItemGroup>
      <HelixWorkItemOrXHarnessTest Include="@(HelixWorkItem)" />
      <HelixWorkItemOrXHarnessTest Include="@(XHarnessAppBundleToTest)" />
      <HelixWorkItemOrXHarnessTest Include="@(XHarnessApkToTest)" />
    </ItemGroup>

    <Message Condition="'$(Scenario)' != ''" Importance="High" Text="Done building Helix work items for scenario $(Scenario). Work item count: @(HelixWorkItemOrXHarnessTest->Count())" />
    <Message Condition="'$(Scenario)' == ''" Importance="High" Text="Done building Helix work items. Work item count: @(HelixWorkItemOrXHarnessTest->Count())" />

    <Message Text="HelixCorrelationPayload: %(HelixCorrelationPayload.Identity)" Condition="'$(HelixDryRun)' == 'true'" Importance="High" />
    <Message Text="HelixWorkItem: %(HelixWorkItem.Identity), Command: %(HelixWorkItem.Command), PreCommands: %(HelixWorkItem.PreCommands) with PayloadArchive: %(HelixWorkItem.PayloadArchive)" Condition="'$(HelixDryRun)' == 'true'" Importance="High" />

    <Error Condition="@(HelixWorkItemOrXHarnessTest->Count()) == 0"
           Text="No helix work items, or APKs, or AppBundles found to test" />

    <Error Condition="'%(HelixWorkItem.Identity)' != '' and ('%(HelixWorkItem.PayloadArchive)' == '' or !Exists(%(HelixWorkItem.PayloadArchive)))"
           Text="Missing PayloadArchive for @(HelixWorkItem)" />

    <Error Text="Stopping the build for dry run" Condition="'$(HelixDryRun)' == 'true'" />
  </Target>

  <Target Name="PrintHelixQueues">
    <Message Importance="High" Text="Using Queues: $(HelixTargetQueues)" />
    <Message Condition="'$(Scenario)' == 'BuildWasmApps'" Importance="High"
             Text="Scenario: $(Scenario), TestUsingWorkloads: $(TestUsingWorkloads), TestUsingWebcil: $(TestUsingWebcil)" />
  </Target>

  <Target Name="PrintBuildTargetFramework">
    <Message Importance="High" Text="Build TargetFramework: $(BuildTargetFramework)" />
  </Target>

  <!--
      Helix tasks will attempt to write a .payload file to the payload directory. But if the
      directory is not writable, for example when it is a system installed dependency like
        `WASI_SDK_PATH=/usr/local/wasi-sdk`
      .. then we need to stage that before passing the path to helix like under `artifacts/obj/helix-staging`
  -->
  <Target Name="StageDependenciesForHelix" Condition="@(__HelixDependenciesToStageThatDontExist->Count()) > 0">
    <Error Condition="'%(__HelixDependenciesToStageThatDontExist.SourcePath)' == '' or !Exists(%(__HelixDependenciesToStageThatDontExist.SourcePath))"
           Text="Could not find %(__HelixDependenciesToStageThatDontExist.Name) at %(__HelixDependenciesToStageThatDontExist.SourcePath), needed to provision for running tests on helix" />

    <ItemGroup>
      <__HelixDependenciesToStageThatDontExist Name="%(FileName)" />
    </ItemGroup>

    <Message Importance="High" Text="Using %(__HelixDependenciesToStageThatDontExist.Name): %(__HelixDependenciesToStageThatDontExist.SourcePath)" />
    <MakeDir Directories="%(__HelixDependenciesToStageThatDontExist.Identity)" />

    <ItemGroup>
      <_FilesToStage Remove="@(_FilesToStage)" />
      <_FilesToStage Include="%(__HelixDependenciesToStageThatDontExist.SourcePath)\**\*"
                     Exclude="%(__HelixDependenciesToStageThatDontExist.SourcePath)\.git\**\*"
                     DirName="@(__HelixDependenciesToStageThatDontExist->'%(Name)')" />
    </ItemGroup>

    <Copy SourceFiles="@(_FilesToStage)"
          DestinationFiles="@(_FilesToStage -> '$(HelixDependenciesStagingPath)\%(DirName)\%(RecursiveDir)%(FileName)%(Extension)')"
          SkipUnchangedFiles="true" />
  </Target>
</Project>
